package com.dubbo.controller;

import com.dubbo.common.check.CheckUtil;
import com.dubbo.domain.User;
import com.dubbo.service.business.address.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 收货地址
 * @author Administrator
 * @date 2018年12月17日 下午4:47:36
 */
@Controller
@RequestMapping("/address")
public class AddressController {


	@Autowired
	private AddressService addressService;
	
	/**
	 * 显示收货地址
	 * 
	 * @author gujiahua
	 * 2018年12月17日 下午4:47:53
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/display.wx")
	@ResponseBody
	public Map<String, Object> displayAddress(HttpServletRequest request,Long pageStart,Long pageTotal) throws Exception{
//		User user = (User) CheckUtil.checkOline3(request);
//		return addressService.displayAddress(user.getId(),pageStart,pageTotal);
		return addressService.displayAddress("da2bcad27b504fa7839664394780cbe3",pageStart,pageTotal);
	}
	
	/**
	 * 新增收货地址
	 * 
	 * @author gujiahua
	 * 2018年12月17日 下午4:48:02
	 * @param request
	 * @param addressJson
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/add.wx")
	@ResponseBody
	public Map<String, Object> addAddress(HttpServletRequest request,String addressJson) throws Exception{
		User user = (User)CheckUtil.checkOline3(request);
		return addressService.addAddress(user.getId(),addressJson);
	}
	
	/**
	 * 修改收货地址
	 * 
	 * @author gujiahua
	 * 2018年12月17日 下午4:48:09
	 * @param request
	 * @param addressJson
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/update.wx")
	@ResponseBody
	public Map<String, Object> updateAddress(HttpServletRequest request,String addressJson) throws Exception{
		User user = (User)CheckUtil.checkOline3(request);
		return addressService.updateAddress(user.getId(),addressJson);
	}
	
	/**
	 * 删除收货地址
	 * 
	 * @author gujiahua
	 * 2018年12月17日 下午4:48:16
	 * @param request
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/delete.wx")
	@ResponseBody
	public Map<String, Object> deleteAddress(HttpServletRequest request,String addressId) throws Exception{
		CheckUtil.checkOline3(request);
		return addressService.deleteAddress(addressId);
	}
	
	/**
	 * 修改默认地址
	 * 
	 * @author gujiahua
	 * 2018年12月17日 下午4:48:22
	 * @param request
	 * @param addressJson
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/updateDef.wx")
	@ResponseBody
	public Map<String, Object> updateDefaultaddress(HttpServletRequest request,String addressJson) throws Exception{
		User user = (User)CheckUtil.checkOline3(request);
		return addressService.updateDefaultaddress(user.getId(),addressJson);
	}
	
	/**
	 * 获取用户的默认地址
	 * 
	 * @author gujiahua
	 * 2018年12月17日 下午4:48:29
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/getDefault.wx")
	@ResponseBody
	public Map<String, Object> getOneDefaultaddress(HttpServletRequest request) throws Exception{
		User user = (User) CheckUtil.checkOline3(request);
		return addressService.getOneDefaultaddress(user.getId());
	}

	/**
	 * 获取修改地址详情
	 * @author wujunyuan
	 * @date 2018年12月28日  下午5:28:06
	 * @param request
	 * @param addressId 修改地址原id
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/getUpdateDefault.wx")
	@ResponseBody
	public Map<String, Object> getUpdateDefaultAddress(HttpServletRequest request,String addressId) throws Exception{
		CheckUtil.checkOline3(request);
		return addressService.getUpdateDefaultAddress(addressId);
	}
}
